package com.roc.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.roc.dao.DaoException;
import com.roc.dao.IAnnounceDao;
import com.roc.dao.IBaseDao;
import com.roc.pojo.Announcement;
import com.roc.service.IAnnounceService;
import com.roc.service.ServiceException;
@Service
@Transactional
public class AnnounceServiceImpl implements IAnnounceService {

	static Logger logger=Logger.getLogger(AnnounceServiceImpl.class);
	@Autowired
	private IBaseDao baseDao;
	@Autowired
	private IAnnounceDao announceDao;
	
	
	@Override
	public List<Announcement> queryAnnouncement() throws ServiceException {
		// TODO Auto-generated method stub
		try{
			baseDao.queryAll("from Announcement a  ");
		}catch(DaoException e){
			e.printStackTrace();
			logger.error("查询公告出错",e); 
		}
		return null;
	}

	@Override
	public void addAnnouncement(Announcement ann) throws ServiceException {
		// TODO Auto-generated method stub
		try{
			baseDao.editSave(ann);
		}catch(DaoException e){
			e.printStackTrace();
			logger.error("新建公告出错",e); 
		}
	}

	@Override
	public void editSaveAnnouncement(Announcement ann) throws ServiceException {
		// TODO Auto-generated method stub
		try{
			baseDao.editUpdate(ann);
		}catch(DaoException e){
			e.printStackTrace();
			logger.error("修改ia公告出错",e); 
		}
	}

	@Override
	public Announcement queryAnnouncementById(Long id) throws ServiceException {
		// TODO Auto-generated method stub
		Announcement ann = null;
		try{
			ann=(Announcement) baseDao.loadById(id, Announcement.class);
		}catch(DaoException e){
			e.printStackTrace();
			logger.error("查询唯一公告出错",e); 
		}
		return ann;
	}

	@Override
	public void deleteAnnouncementById(Long id) throws ServiceException {
		Announcement ann = null;
		try{
			ann=(Announcement) baseDao.loadById(id, Announcement.class);
			baseDao.delete(ann);
			
		}catch(DaoException e){
			e.printStackTrace();
			logger.error("查询唯一公告出错",e); 
		}
		
	}

	@Override
	public List<Announcement> queryNewAnnouncement() throws ServiceException {
		// TODO Auto-generated method stub
		List<Announcement> ann = null;
		try{
			ann=announceDao.queryNewAnnouncement();
		}catch(DaoException e){
			e.printStackTrace();
			logger.error("查询唯一公告出错",e);
		}
		return ann;
	}

}
